import EChart from './baseECharts';
import settings from '../../config/settings';

export default class FaultLine extends EChart {
    setData(data) {
        let list = data.list;
        let option = {
            color: ['#4184FD', '#00FFFF'],
            title: {
                text: data.title || '告警月趋势',
                textStyle: {
                    fontWeight: 'normal',
                    fontSize: (data.titleFontSize || 0.3) * settings.BASE_SIZE,
                    color: '#00A9F6'
                },
                left: '6%'
            },
            tooltip: {
                trigger: 'axis',
                textStyle: {
                    color: '#ffffff',
                    fontSize: (data.tipTextSize || 0.2) * settings.BASE_SIZE
                }
            },
            legend: {
                data: ['报警', '处理'],
                textStyle: {
                    color: '#00A9F6',
                    fontSize: (data.fontSize || 0.2) * settings.BASE_SIZE
                }
            },
            grid: {
                right: '5%'
            },
            xAxis: [
                {
                    type: 'category',
                    data: list.map(t => t.timeValue),
                    axisLine: {
                        lineStyle: {
                            color: data.titleFontColor || '#00A9F6',
                            width: 0.02 * settings.BASE_SIZE
                        }
                    },
                    axisLabel: {
                        margin: 0.1 * settings.BASE_SIZE,
                        textStyle: {
                            fontSize:
                                (data.fontSize || 0.2) * settings.BASE_SIZE
                        }
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',

                    axisLabel: {
                        color: data.titleFontColor || '#00A9F6',
                        formatter: '{value}',
                        textStyle: {
                            fontSize:
                                (data.fontSize || 0.2) * settings.BASE_SIZE
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: data.titleFontColor || '#00A9F6'
                        }
                    }
                }
            ],
            series: [
                {
                    name: '报警',
                    type: 'bar',
                    barGap: '15%',
                    data: list.map(t => t.alarmCount)
                },
                {
                    name: '处理',
                    type: 'bar',
                    barGap: '15%',
                    data: list.map(t => t.detailCount)
                }
            ]
        };

        this.setOption(option);
    }
}
